﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using EntityFrameworkETL.Extensions;
using EntityFrameworkETL.HelloWorld.Models;
using EntityFrameworkETL.Interceptors;

namespace EntityFrameworkETL.HelloWorld
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();

            using (var context = new UsersContext())
            {
                var worlds = new List<World>();
                var earth = new World("Earth");
                var keys  = MetadataWorkspaceExtensions.GetTableKeyColumns(context, typeof (World));
                earth.Persons.Add(new Person("Chris"));
                var megan = new Person("Person1");
                megan.Jobs.Add(new Job("Job1"));
                megan.Jobs.Add(new Job("Job2"));
                earth.Persons.Add(megan);
                earth.Persons.Add(new Person("Person2"));
                worlds.Add(earth);
                var mars = new World("Mars");
                var perrin = new Person("Person2");
                perrin.Jobs.Add(new Job() { Name = "FirstJob" });
                mars.Persons.Add(perrin);
                mars.Persons.Add(new Person("PERSON3"));
                var mom = new Person("Person4");
                mom.Jobs.Add(new Job("test1"));
                mom.Jobs.Add(new Job("test2"));
                mom.Jobs.Add(new Job("test3"));
                mom.Jobs.Add(new Job("test4"));
                mars.Persons.Add(mom);
                worlds.Add(mars);

                context.Worlds.AddRange(worlds);
                context.SaveBatchedChanges();
            }
        }
    }
}